<?php

class foreEndAPI extends CI_Controller
{
    function __construct()
    {
        parent::__construct();
        $this->load->library(array('session', 'pagination'));
        $this->load->helper(array('url', 'form', 'date'));
        $this->load->database();
    }

    //登录接口
    function forLogin()
    {
        if ($this->input->post()) {
            $this->load->model("APIModel");
            $res = $this->APIModel->checkLogin();
            if ($res) {
                foreach ($res as $value) {
                    $info['sNum'] = $value['sNum'];
                    $info['sName'] = $value['sName'];
                }
                echo $te = json_encode(array('error' => '1', 'info' => $info));
            } else {
                echo json_encode(array('error' => '0', 'info' => ''));
            }
        } else {
            echo json_encode(array('error' => '0', 'info' => ''));
        }
        //var_dump(json_decode(""));
    }

    //校新闻，院新闻，其他
    function getNews()
    {
        $typeId = 4;
        $sql = "select * from newsInforms where typeId = ?";
        $res = $this->db->query($sql, array("$typeId"));
        if (!$res) {
            echo json_encode(array("error" => 1));
        } else {
            echo json_encode(array(
                "error" => 0,
                "table" => $res->result_array()));
        }
    }

    //校通知，院通知，辅导员通知
    function getInform()
    {

    }

    //校园跑跑一元兼职
    function getPartTimeJobs()
    {

    }

    //二手市场
    function getSecondHandThings()
    {

    }

    //招聘信息
    function getRecruitInformation()
    {

    }

    //校园广告
    function getSchoolAds()
    {

    }

    //寻找导游,领取导游students表
    function getGuiders()
    {


    }

    //用户需求信息列表
    function getCustomNeeds()
    {
        $sql = "select * from trapneeds";
        $res = $this->db->query($sql, array(""));
        if (!$res) {
            echo json_encode(array("error" => 1));
        } else {
            echo json_encode(array(
                "error" => 0,
                "table" => $res->result_array()));
        }
    }

    //我的需求（需求列表）
    function getMyNeeds()
    {
        $id = $this->input->post("id");//用户登录时的id号
        $sql = "select * from trapNeeds where studentId = ?";
        $res = $this->db->query($sql, array("$id"));
        if (!$res) {
            echo json_encode(array("error" => 1));
        } else {
            echo json_encode(array(
                "error" => 0,
                "table" => $res->result_array()));
        }
    }

    //来应聘的导游(可以有多个)(iAmGuider表)
    function getRecruitGuiders()
    {
        $id = $this->input->post("trapNeedsId");
        $sql = "select * from iamguider , students where students.id=iamguider.studentId and iamguider.trapNeedsId=?";
        $res = $this->db->query($sql, array("$id"));
        if (!$res) {
            echo json_encode(array("error" => 1));
        } else {
            echo json_encode(array(
                "error" => 0,
                "table" => $res->result_array()));
        }
    }

    //查看详情
    function getDetailInformation()
    {
        $id = $this->input->post("studentId");//循环应聘者或其他保留的学生id。
        $sql = "select * from students where id=?";
        $res = $this->db->query($sql, array("$id"));
        if (!$res) {
            echo json_encode(array("error" => 1));
        } else {
            echo json_encode(array(
                "error" => 0,
                "table" => $res->result_array()));
        }
    }

    //用户已选导游（只能选择一个）(trapNeeds表)  （显示上面的需求列表。然后在各项需求列表下查看我选的导游）
    function getMyGuiders()
    {
        $id = $this->input->post("trapNeedsId");
        $sql = "select * from trapneeds,students where trapneeds.studentId = students.id and trapNeeds.id=?";
        $res = $this->db->query($sql, array("$id"));
        if (!$res) {
            echo json_encode(array("error" => 1));
        } else {
            echo json_encode(array(
                "error" => 0,
                "table" => $res->result_array()));
        }

    }


    //我要当导游,我领取得任务（iAmGuider表）
    function getMyCustoms()
    {
        $id = $this->input->post("id");//登录时的保存的id
        $sql = "select * from iamguider,trapneeds where iamguider.trapNeedsId=trapneeds.id and  studentId = ?";
        $res = $this->db->qeury($sql, array("$id"));
        if (!$res) {
            echo json_encode(array("error" => 1));
        } else {
            echo json_encode(array(
                "error" => 0,
                "table" => $res->result_array()));
        }
    }
}